//路由器
app.config(function($routeProvider){
    $routeProvider.
    when("/",{
       controller: 'watch_state',
       templateUrl: 'view/watch_state.html',
        resolve : {
          async : getJSON(urlAddress + "/home/decetion/json/watch_state.json")
       }
    }).
    when("/index",{
       //首页，默认消息通知页面
       controller: 'watch_state',
       templateUrl: 'view/watch_state.html',
        resolve : {
          async : getJSON(urlAddress + "/home/decetion/json/watch_state.json")
       }
    }).
    when("/watch_state",{
       //消息通知页面
       controller: 'watch_state',
       templateUrl: 'view/watch_state.html',
        resolve : {
          async : getJSON(urlAddress + "/home/decetion/json/watch_state.json")
       }
    }).
    otherwise({
       redirectTo:'/'
    });
});

// 手表状态检测
app.controller('watch_state',["$scope","async",function($scope,msg) {
             //设备总数
             $scope.number = 3227;
             //当前的页数
             $scope.nowPage = 1;
             // 最大的页数
             $scope.maxPage = 10;
             $scope.pageN = $scope.nowPage;

             // 分页功能
             $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
             $scope.afterLi = $scope.pageA.afterLi;
             $scope.beforeLi = $scope.pageA.beforeLi;
             $scope.pageArr = $scope.pageA.arr;
             $scope.hasLastPage = $scope.pageA.hasLastPage;

             $("pages li").each(function() {
                  var n = parseInt($(this).html());
             })

             // 设置初始的状态筛选条件和行数显示
             $scope.states = [
               {state : "在线", str: "在线"},
               {state : "离线", str: "离线"},
               {state : "全部", str: ""},
             ]
             $scope.stateStr = $scope.states[2];
             $scope.lineNumbers = [10,15,20];
             $scope.lineNumber = $scope.lineNumbers[0];

             //将获取的数据跟传给控制器
             $scope.opints = msg;
             if ($scope.opints.length < 1) {
                 $scope.hasSign = true;
             } else {
                 $scope.hasSign = false;
             }

              //删除用户
              $scope.delUser = function() {
                // 获取所有被选中的元素及其对应的用户ID
                var delID = [];
                $("table td input").each(function() {
                   if ($(this).prop("checked")) {
                      delID.push($(this).parents("tr").attr("userID"));
                   };
                })
                 if(delID.length == 0) {
                   alert("你没有选择任何设备");
                 } else {
                  console.log(delID);
                    // window.location.reload();
                 }
              }

              // 全选效果以及反选
              allChecked();

              //设置导航栏中当前页面的背景色
             navTitClass($("nav .watch_state").parent().eq(0));
}])